import React, {FC, useCallback, useMemo} from "react";
import ListPage from "../common/ListPage.tsx";
import {treeMap} from "../../utils";

interface MaintenancePageProps {
}

const MaintenancePage: FC<MaintenancePageProps> = (props) => {
    const isRowSelectable = useCallback(({data}) => {
        return data.isParent;
    }, []);

    const renderMaintenancePage = useMemo(() => {
        return (
            <ListPage
                {...props}
                isRowSelectable={isRowSelectable}
                rowKey="virtualId"
                dataSourceFilter={(data) => {
                    return treeMap(data, (children = [], item) => {
                        return {
                            ...item,
                            children: children.length ? children : undefined,
                            virtualId: Math.floor(Math.random() * 1000000000) + ""
                        }
                    })
                }}
            />
        )
    }, [props]);

    return (renderMaintenancePage);
};

export default React.memo(MaintenancePage);